<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<form action="/cron/group_share.php">
<input type="text" id="ucode" name="ucode" value="<?php echo $_GET['uid']; ?>"><input type='submit' name='submit' value="Check" />
</form>

<?php
set_time_limit(0);
$root=preg_replace('/cron$/', '', dirname(__FILE__));

require_once($root."inc.config.php");

require_once($root."initialize.php");


$no=0;
$uid = $_GET['uid'];
$ucode = $_GET['ucode'];
if($ucode>0){
if(($db_msg=cron_initialize()) !== true){
	print_r("Connection error");
}else{
	if($uid>0)
		$record_sql="select gg_users.code, gg_users.name, gg_users.ewallet, gg_users.mwallet, sum(gg_share.total_unit) as total_share from gg_users inner join gg_users sponsor on sponsor.id=".$uid." and gg_users.ref_left between sponsor.ref_left and sponsor.ref_right left join gg_share on gg_share.uid=gg_users.id and gg_share.sell_price='0.00' and gg_share.replica=0 where gg_users.id not in (81,934) and gg_users.status='normal' group by gg_users.name order by code";
	elseif($ucode<>"")
		$record_sql="select gg_users.code, gg_users.name, gg_wallet.ewallet, gg_wallet.mwallet, gg_share.buy_price, sum(gg_share.total_unit) as total_share, gg_earn.total_earn, gg_bill.total_bill from gg_users inner join gg_users sponsor on sponsor.code='{$ucode}' and gg_users.ref_left between sponsor.ref_left and sponsor.ref_right left join gg_share on gg_share.uid=gg_users.id and gg_share.sell_price='0.00' and gg_share.replica=0 and gg_share.status=0 left join gg_earn on gg_earn.name=gg_users.name left join gg_bill on gg_bill.name=gg_users.name left join gg_wallet on gg_wallet.name=gg_users.name where gg_users.id not in (81,934,1) and gg_users.status='normal' group by gg_users.name order by gg_earn.total_earn,gg_users.cdate";
	else
		$record_sql="select gg_users.code, gg_users.name, gg_wallet.ewallet, gg_wallet.mwallet, gg_share.buy_price, sum(gg_share.total_unit) as total_share, gg_earn.total_earn, gg_bill.total_bill from gg_users left join gg_share on gg_share.uid=gg_users.id and gg_share.sell_price='0.00' and gg_share.replica=0 and gg_share.status=0 left join gg_earn on gg_earn.name=gg_users.name left join gg_bill on gg_bill.name=gg_users.name left join gg_wallet on gg_wallet.name=gg_users.name where gg_users.id not in (81,934,1) and gg_users.status='normal' group by gg_users.name order by gg_earn.total_earn,gg_users.cdate";

	$t = @mysql_num_rows($r=mysql_query($record_sql));
	
	if($t<=0)
	{
		print_r("no record");
		exit;
	}
	
	echo "<table border='1'><tr><td>No.</td><td>Code</td><td>Name</td><td>Share Unit</td><td>Share Price * 3.70</td><td>E-Wallet</td><td>Maintenance</td><td>Total</td><td>*0.65</td><td>20%</td><td>Bonus Income</td></tr>";
	$i=0;
	$total=0;
	$total_bonus=0;
	$total_bill=0;
	while($user = mysql_fetch_assoc($r))
	{		
		if($user["total_share"]>0){
			$i++;
			echo "<tr><td>".$i."</td><td>".$user['code']."</td><td>".$user['name']." (".$user['total_bill'].")"."</td><td align='right'>".$user['total_share']."</td><td align='right'>".number_format($user['total_share']*3.7,2,".","")."</td><td align='right'>".number_format($user['ewallet'],2,".","")."</td><td align='right'>".number_format($user['mwallet'],2,".","")."</td><td align='right'>".number_format(($user['total_share']*3.7)+$user['ewallet']+$user['mwallet'],2,".","")."</td><td align='right'>".number_format((($user['total_share']*3.7)+$user['ewallet']+$user['mwallet'])*0.65,2,".","")."</td><td align='right'>".number_format(((($user['total_share']*3.7)+$user['ewallet']+$user['mwallet'])*0.65)*0.2,2,".","")."</td><td align='right'>".$user['total_earn']."</td></tr>";
			$total+=number_format(($user['total_share']*3.7)+$user['ewallet']+$user['mwallet'],2,".","");
			$total_bill+=$user['total_bill'];
			//$total_bonus+=number_format($user['total_earn'],2,".","");
		}
	}
	echo "<tr><td colspan=7 align='right'>Total</td><td align='right'>".number_format($total,2,".","")."</td><td align='right'></td></tr>";
	echo "</table>";



/*
	if($record_sql=="select gg_users.code, gg_users.name, gg_users.ewallet, gg_users.mwallet, gg_share.buy_price, sum(gg_share.total_unit) as total_share from gg_users left join gg_share on gg_share.uid=gg_users.id and gg_share.sell_price='0.00' and gg_share.replica=0 where gg_users.id not in (81,934) and gg_users.status='normal' group by gg_users.name, gg_share.buy_price order by code"){
	
	echo "<table border='1'><tr><td>No.</td><td>Code</td><td>Name</td><td>Purchase Price</td><td>Share Unit</td><td>Share Price * 3.70</td></tr>";
	$i=0;
	while($user = mysql_fetch_assoc($r))
	{		
		if($user["total_share"]>0){
			$i++;
			echo "<tr><td>".$i."</td><td>".$user['code']."</td><td>".$user['name']."</td><td align='right'>".$user['buy_price']."</td><td align='right'>".$user['total_share']."</td></tr>";
		}
	}
	echo "</table>";

	}else{

	echo "<table border='1'>";
	$i=0;
	while($user = mysql_fetch_assoc($r))
	{		
		if($user["total_share"]>0){
			$i++;
			echo "<tr><td>".$i."</td><td>".$user['code']."</td><td>".$user['name']."</td><td align='right'>".$user['total_share']."</td></tr>";
		}
	}
	echo "</table>";

	}
*/

}
}
exit;		
?>